<?php
class Administration_Form_Teams extends Jnd_Form
{
    
    protected $_decorator = "Formulairejnd";

    public function __construct( $decorateur = "Formulairejnd", $options = null )
    {
        $this->_decorator = $decorateur;
        parent::__construct($decorateur, $options);
        $this->setElementDecorators(array(
            "$decorateur"
        ), array(
            'logo'
        ), false);
    }

    public function init()
    {
        //
        // On ajoute le champ id
        $this->addElement('text', 'id', array(
            'label' => 'Id', 
            'readonly' => 'readonly', 
            'class' => 'readonly', 
            'filters' => array(
                'Digits'
            )
        ));
        
        //
        //  Champ Nom
        $this->addElement("text", "name", array(
            'label' => 'Nom', 
            'required' => true, 
            'filters' => array()
        ));
        
        //
        //  Champ creationUser
        $storage = (object) Zend_Auth::getInstance()->getStorage()->read();
        $this->addElement("text", "creationUser", array(
            'label' => __('Created by'), 
            'readonly' => 'readonly', 
            'class' => 'readonly', 
            'value' => $storage->username
        ));
        
        //
        //  Champ creationDate
        $this->addElement("text", "creationDate", array(
            'label' => __('Created'), 
            'readonly' => 'readonly', 
            'class' => 'readonly', 
            'value' => date(Jnd_Global_Constantes::FORMAT_DATE_WEB_LONG)
        ));
        
        if ($this->_decorator != "Voir") {
            //
            //  Champ logo
            $element = new Zend_Form_Element_File('logo');
            $element->setLabel(__('Choose a logo'))->setDestination(dirname(APPLICATION_PATH) . "/public/images/teams/logos");
            // ensure only 1 file
            $element->addValidator('Count', false, 1);
            // limit to 100K
            $element->addValidator('Size', false, 102400);
            // only JPEG, PNG, and GIFs
            $element->addValidator('Extension', false, 'jpg,jpeg,png,gif');
            //        $element->setDecorators(array("Formulaireddb"));
            $this->addElement($element, 'logo');
        } else {
        	$element = new Zend_Form_Element_Image("logo");
        	$this->addElement($element);
        }
        
        $this->setName("teams");
    }

}